home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / game / role / World.lha / source / wbstuff.c < prev    next >
C/C++ Source or Header  |  2001-03-06  |  4KB  |  253 lines

  1. #include "exec/types.h" 
  2. #include "exec/memory.h" 
  3. #include "exec/io.h"
  4. #include "exec/libraries.h"
  5. #include "exec/execbase.h"
  6. #include "libraries/dos.h" 
  7. #include "libraries/dosextens.h"
  8. #include "workbench/startup.h"
  9. #include "workbench/workbench.h"
  10. #include <ctype.h>
  11. #include <functions.h>
  12.  
  13. #define NOBUF 512
  14.  
  15. char Q1TEXT[80] =    "q1text.dat";
  16. extern int q1text_dat;
  17.  
  18. struct FileHandle *tty;
  19.  
  20. char    obuf[NOBUF];    /* Output buffer        */
  21. static char *ob = obuf;
  22. int nobuf;              /* # of bytes in above      */
  23.  
  24. extern struct WBStartup *WBenchMsg;
  25.  
  26. struct Library *IconBase = NULL;
  27.  
  28. char WindowName[256] = "NEWCON:0/0/640/200/   World   ";
  29.  
  30. AmigaInit(argc,argv)
  31. char *argv[]; 
  32. {
  33.    
  34.    if(argc==0)
  35.      getWbArgs(WBenchMsg);
  36.    else
  37.      getCLIargs(argc,argv);
  38. }
  39.  
  40. getWbArgs(wbMsg)
  41. struct WBStartup *wbMsg;
  42. {
  43.    struct WBArg  *wbArg;
  44.    struct DiskObject *diskobj;
  45.    char **toolarray;
  46.    char *s;
  47.    
  48.    struct Lock *olddir;
  49.    
  50.  
  51.    /* Defaults */
  52.  
  53.    wbArg = wbMsg->sm_ArgList;
  54.    
  55.    if((IconBase = OpenLibrary("icon.library", 0L)))
  56.    {
  57.       diskobj=(struct DiskObject *)GetDiskObject(wbArg->wa_Name);
  58.       if(diskobj)
  59.       {
  60.          toolarray = (char **)diskobj->do_ToolTypes;
  61.  
  62.          if(s=(char *)FindToolType(toolarray,"WIN"))  strcpy(WindowName,s);
  63.          FreeDiskObject(diskobj);
  64.       }
  65.       CloseLibrary(IconBase);
  66.    }
  67.    
  68.    ttopen();
  69.  
  70.    if(wbMsg->sm_NumArgs > 1L)       /* use second arg as file instead */
  71.    {                               /* of "q1text.dat" */
  72.      wbArg++;
  73.      
  74.      if(wbArg->wa_Lock==NULL)
  75.      {
  76.        printf("Could not open file %s!\n",Q1TEXT);
  77.        ttclose();
  78.        _exit(20L);
  79.      }
  80.      
  81.      olddir=CurrentDir(wbArg->wa_Lock);
  82.      
  83.      q1text_dat = open(Q1TEXT,0);    /* open data file */
  84.      
  85.      if(q1text_dat<0)
  86.      {
  87.        printf("Could not open file %s!\n",Q1TEXT);
  88.        ttclose();
  89.        _exit(20L);
  90.      }
  91.      
  92.      CurrentDir(olddir);
  93.      
  94.    }
  95.    else
  96.    {
  97.      q1text_dat = open(Q1TEXT,0);    /* open data file */
  98.      
  99.      if(q1text_dat<0)
  100.      {
  101.        printf("Could not open file %s!\n",Q1TEXT);
  102.        ttclose();
  103.        _exit(20L);
  104.      }
  105.    }
  106.      
  107. }
  108.  
  109. getCLIargs(argc,argv)
  110. int argc;
  111. char *argv[];
  112. {
  113.   int arg;
  114.   int lace, newcon;
  115.   
  116.   lace=FALSE;
  117.   newcon=TRUE;
  118.   for(arg=1;arg<argc;arg++)
  119.   {
  120.     if(argv[arg][0]=='-')
  121.     {
  122.       switch(argv[arg][1])
  123.       {
  124.         case 'n':     /* use NEWCON: window */
  125.           newcon=TRUE;
  126.           break;
  127.      
  128.         case 'c':    /* use CON: window */
  129.           newcon=FALSE;
  130.           break;
  131.            
  132.         case 'i':    /* use 400 line interlaced window */
  133.           lace=TRUE;
  134.           break;
  135.           
  136.         case 'N':   /* use 200 line (non-interlaced) window */
  137.           lace=FALSE;
  138.           break;
  139.              
  140.         default:     /* ignore */
  141.           ;
  142.  
  143.       }
  144.     }
  145.     else
  146.     {
  147.       strcpy(Q1TEXT,argv[arg]);        /* alternate name for data file */
  148.     }
  149.   }
  150.      
  151.    
  152.   if(newcon && lace)
  153.     strcpy(WindowName,"NEWCON:0/0/640/400/   WORLD   ");
  154.   if(newcon && !lace)
  155.     strcpy(WindowName,"NEWCON:0/0/640/200/   WORLD   ");
  156.   if(!newcon && lace)
  157.     strcpy(WindowName,"CON:0/0/640/400/   WORLD   ");
  158.   if(!newcon && !lace)
  159.     strcpy(WindowName,"CON:0/0/640/200/   WORLD   ");
  160.   ttopen();
  161.   
  162.   q1text_dat = open(Q1TEXT,0);    /* open data file */
  163.      
  164.   if(q1text_dat<0)
  165.   {
  166.     printf("Could not open file %s!\n",Q1TEXT);
  167.     ttclose();
  168.     _exit(20L);
  169.   }
  170. }   
  171.  
  172. ttopen()
  173. {
  174.     
  175.     nobuf=0;
  176.  
  177.     tty = Open(WindowName, MODE_NEWFILE);
  178.     if (tty == NULL)
  179.         exit(20);
  180. }
  181.  
  182.  
  183. ttclose()
  184. {
  185.     char t[256];
  186.     
  187.     printf("Press Return...");
  188.     gets(t);
  189.     if (tty != NULL) {
  190.         ttflush();
  191.         Close(tty);
  192.     }
  193.     tty = NULL;
  194. }
  195.  
  196.  
  197. getc()
  198. {
  199.     char c;
  200.     int result;
  201.  
  202.     do
  203.     {
  204.         flush();
  205.         result = Read(tty, &c, 1L);
  206.     } while (result != 1);
  207.     return (c & 0177);
  208. }
  209.  
  210.  
  211. flush()
  212. {
  213.  
  214.     ttflush();
  215.     Write(tty, obuf, (long) ob-obuf);
  216.     ob = obuf;
  217. }
  218. /*
  219.  * This function does the real work of
  220.  * flushing out buffered I/O on the Amiga. All
  221.  * we do is blast out the block with a write call.
  222.  */
  223.  
  224.  
  225. ttflush()
  226. {
  227.     if (nobuf > 0) {
  228.         Write(tty, obuf, (long) nobuf);
  229.         nobuf = 0;
  230.     }
  231. }
  232.  
  233.  
  234.  
  235.  
  236. /*
  237.  * Output a character.
  238.  */
  239. putc(c)
  240. int c;
  241. {
  242.     if (ob >= &obuf[sizeof(obuf)])
  243.         flush();
  244.  
  245.     if(c=='\n')
  246.     {
  247.       *ob++ = c;
  248.       flush();
  249.     }
  250.     else
  251.       *ob++ = c;
  252. }
  253.